import Vue from 'vue'
import App from './App'
import router from './router/'
import './config/http'
import './config/flexible'
import './config/fastclick'
import 'mint-ui/lib/style.css'
import './style/swiper.min.css'
import {setStore,getStore} from '@/config/mUtils';
if ('addEventListener' in document) {
  document.addEventListener('DOMContentLoaded', function () {
    FastClick.attach(document.body);
  }, false);
}


window.onload = function () {
  document.addEventListener('touchstart', function (event) {
    console.log(event);
    if (event.touches.length > 1) {
      event.preventDefault();
    }
  })
  var lastTouchEnd = 0;
  document.addEventListener('touchend', function (event) {
    var now = (new Date()).getTime();
    if (now - lastTouchEnd <= 300) {
      event.preventDefault();
    }
    lastTouchEnd = now;
  }, false)
}
router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
    if (getStore('Token')) { // 判断当前的token是否存在
      next();
    } else {
      next({
        path: '/login',
        query: {
          redirect: to.fullPath
        } // 将跳转的路由path作为参数，登录成功后跳转到该路由
      })
    }
  } else {
    next();
  }
});
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: {
    App
  }
})
